#define DEBUG
#include <cstdio>

using namespace std;

const int mods=998244353, maxt=10000;

long long qpower(long long a, int n, int mods) {
  long long s=1;
  for (; n>1; n/=2) {
    if (n%2) {
      s = s*a%mods;
    }
    a = a*a%mods;
  }
  return s*a%mods;
}

int solve(int n, int m) {
  static bool book[maxt+1];
  static int prime[maxt+1], ans[maxt+1];
  prime[0] = 0;
  for (int i=2; i<=n; i++) {
    book[i] = false;
  }
  int ret=1;
  for (int i=2; i<=n; i++) {
    if (!book[i]) {
      ans[i] = qpower(i, m%(n-1), n);
      prime[++prime[0]] = i;
    }
    for (int j=1; j<=prime[0] && i*prime[j]<=n; j++) {
      book[i*prime[j]] = true;
      ans[i*prime[j]] = ans[i]*ans[prime[j]]%n;
      if (i%prime[j]==0) {
	break;
      }
    }
    if (ans[i]-i%n==0) {
      ret++;
    }
  }
  return ret;
}

int main() {
  freopen("division.in", "r", stdin);
  freopen("division.out", "w", stdout);

  int id, t, c, m;
  scanf("%d %d", &id, &t);
  for (int ti=1; ti<=t; ti++) {
    scanf("%d %d", &c, &m);
    long long ans=1;
    for (int i=1; i<=c; i++) {
      int t;
      scanf("%d", &t);
      ans = ans*solve(t, m)%mods;
    }
    printf("%lld\n", ans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
